import { defineBoot } from "#q-app/wrappers";
import { createI18n } from "vue-i18n";
import { Quasar } from "quasar";
// import type messages from "src/i18n";
import messages from "src/i18n";

export type MessageLanguages = keyof typeof messages;
// Type-define 'en-US' as the master schema for the resource
const lang = Quasar.lang.getLocale();
console.log(lang);
export type MessageSchema = (typeof messages)["zh-CN"];

// See https://vue-i18n.intlify.dev/guide/advanced/typescript.html#global-resource-schema-type-definition
/* eslint-disable @typescript-eslint/no-empty-object-type */
declare module "vue-i18n" {
  // define the locale messages schema
  export interface DefineLocaleMessage extends MessageSchema {}

  // define the datetime format schema
  export interface DefineDateTimeFormat {}

  // define the number format schema
  export interface DefineNumberFormat {}
}
/* eslint-enable @typescript-eslint/no-empty-object-type */

export const i18n = createI18n<{ message: MessageSchema }, MessageLanguages>({
  legacy: false,
  globalInjection: true,
  locale: lang as string,
  messages: messages
});

export default defineBoot(({ app }) => {
  // Set i18n instance on app
  app.use(i18n);
});
